import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mahjong/entity/card/MahjongCardEntity.dart';

class LeftGameCommons {
  static Positioned buildVerticalCard(
      double backGroudHeight, String backgroundImg) {
    return Positioned(
        top: ScreenUtil().screenHeight / 10,
        left: backGroudHeight * 1.5,
        child: Container(
            width: 100,
            height: 500,
            child: Stack(
              children: buildUserCard(
                  13, ScreenUtil().screenWidth / 7, backgroundImg),
            )));
  }

  static List<Positioned> buildUserCard(
      int number, double top, String backgroundImg) {
    List<Positioned> result = [];
    for (int i = 0; i <= number; i++) {
      bool last = (i == number && number % 3 == 2);
      result.add(Positioned(
          top: last
              ? ScreenUtil().screenWidth / 45 * i + 20
              : ScreenUtil().screenWidth / 45 * i,
          child: Image.asset(
            backgroundImg,
            width: ScreenUtil().screenWidth / 50,
          )));
    }
    return result;
  }

  // 构建当前用户出的手牌

  static Widget buildExportCard(MahjongCardEntity cardInfo, double cardWidth) {
    // 玩家的手牌应该将屏幕分为 16等分
    var backGroudHeight = cardWidth * 1.6;
    return Column(
      children: [
        Container(
          height: backGroudHeight,
          width: cardWidth,
          child: Stack(
            children: [
              Container(
                  width: double.infinity,
                  height: double.infinity,
                  child: Image.asset(
                    cardInfo.cardId == null
                        ? "images/mahjong/user/bottom/export_up.png"
                        : "images/mahjong/user/bottom/usercard_background.png",
                    fit: BoxFit.cover,
                  )),
              cardInfo.highlight
                  ? Container(
                      width: double.infinity,
                      height: double.infinity,
                      color: Colors.blue.withOpacity(0.3),
                    )
                  : SizedBox(),
              cardInfo.cardId == null
                  ? Container()
                  : Align(
                      alignment: const Alignment(0, 0.5),
                      child: Container(
                          width: cardWidth * 0.8,
                          height: cardWidth * 0.8 * 1.27,
                          child: Image.asset(
                            'images/mahjong/card/south_hand_tile_' +
                                cardInfo.cardId.toString() +
                                '.png',
                            fit: BoxFit.cover,
                          ))),
            ],
          ),
        ),
      ],
    );
  }
}
